package com.shambles.manage2.tkmapper.mapper;

import com.shambles.manage2.tkmapper.entity.AbattoirBooth;
import com.shambles.manage2.tkmapper.entity.AbattoirBoothDetail;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.additional.insert.InsertListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

@org.apache.ibatis.annotations.Mapper
public interface AbattoirBoothMapper extends Mapper<AbattoirBooth>, InsertListMapper<AbattoirBooth> {
    List<AbattoirBooth> findAllBooth();

    List<AbattoirBooth> findEmptyBooth();
    /**
     * 根据入场guid查询摊位明细
     */
    @Select("select * from abattoir_booth_detail where admission_guid='${guid}'")
    List<AbattoirBoothDetail> queryBoothDetailByGuid(String guid);
    /**
     * 删除摊位
     */
    @Delete("delete from abattoir_booth  where guid='${guid}'")
    void deleteBooth(@Param("guid") String guid);
    /**
     * 修改摊位
     */
    void updateBooth(AbattoirBooth abattoirBooth);
    /**
     * 查询摊位
     */
    @Select("select * from abattoir_booth")
    List<AbattoirBooth> queryAbattoirBooth();
    /**
     * 查询正在使用的摊位屠宰情况
     */
    @Select("select b.id,b.guid,b.booth_guid,b.type,SUM(b.number) as number,b.subscribe_guid,b.admission_guid,b.cattle_guid from admission_register a ,abattoir_booth_detail b where a.guid=b.admission_guid and a.status=0 GROUP BY b.booth_guid,b.type")
    List<AbattoirBoothDetail> querySlaughter();

    @Update("UPDATE abattoir_booth SET status = ${status} WHERE guid = '${guid}'"  )
    void updateState(@Param("status") int status , @Param("guid") String guid);
    /**
     * 获取摊位用户
     */
    //@Select("select b.admission_personnel_name,SUM(a.number) as total,c.phone from abattoir_booth_detail a ,admission_register b,usersinfo c where a.admission_guid=b.guid and b.booth_guid='${boothGuid}' and b.`status` = 0 AND b.admission_personnel_name=c.name  GROUP BY b.admission_personnel_name,c.name")
    @Select("select b.admission_personnel_name,a.type,a.number,c.phone from abattoir_booth_detail a ,admission_register b,usersinfo c where a.admission_guid=b.guid and b.booth_guid='${boothGuid}' and b.`status` = 0 AND b.admission_personnel_name=c.name")
    List<Map<String,Object>> queryUser(@Param("boothGuid") String boothGuid);
    /**
     * 根据guid查询摊位对象
     */
    @Select("select * from abattoir_booth where guid='${guid}'")
    AbattoirBooth abattoirBooth(@Param("guid") String guid);
    /**
     * 修改摊位为0
     */
    @Update("update abattoir_booth set status=0 where guid='${guid}'")
    void updateAbattoirBoothstatu(@Param("guid") String guid);
    /**
     * 修改摊位状态为1
     */
    @Update("update abattoir_booth set status=1 where guid='${guid}'")
    void updateAbattoirBoothstatus(@Param("guid") String guid);
}